package com.cc.self.ctrl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.enjoyun.bmc.common.util.AppUtil;
import com.enjoyun.bmc.common.util.WebUtil;
import com.enjoyun.bmc.core.service.CoreService;
import com.cc.self.model.raw.SelfFactory;
import com.cc.self.service.SelfFactoryService;


@Controller(value = "com.cc.self.ctrl.SelfFactoryCtrllor")
@RequestMapping("selffactory")
public class SelfFactoryCtrllor {
	@Autowired
	private CoreService aCoreService;
	@Autowired
	private SelfFactoryService aSelfFactoryService;
	
	/**
	 * 根据组织查询列表
	 * @param ono 组织代码
	 * @return SelfFactory[]
	 */
	@RequestMapping(value = "list", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getSelfFactoryList(@RequestParam(value = "bus_id", required = false) Integer bus_id) {
		try{
			aCoreService.assertFunctionAuth("cc/selffactory/start");
			return WebUtil.getSuccessMap(aSelfFactoryService.getSelfFactoryList(bus_id));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}
	
	/**
	 * 获取实体
	 * @param id 主键
	 * @return SelfFactory
	 */
	@RequestMapping(value = "get", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getSelfFactory(@RequestParam(value = "id") int key) {
		try{
			aCoreService.assertFunctionAuth("selffactory/start");
			return WebUtil.getSuccessMap(aSelfFactoryService.getSelfFactory(key));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}

	/**
	 * 创建实体
	 * @param data 实体JSON
	 * @return SelfFactory
	 */
	@RequestMapping(value = "create", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> createSelfFactory(@RequestParam(value = "data") String data) {
		try{
			aCoreService.assertFunctionAuth("selffactory/create");
			SelfFactory entity = AppUtil.toObject(data, SelfFactory.class);
			return WebUtil.getSuccessMap(aSelfFactoryService.createSelfFactory(entity));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}

	/**
	 * 更新实体
	 * @param data 实体JSON
	 * @return SelfFactory
	 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateSelfFactory(@RequestParam(value = "data") String data) {
		try{
			aCoreService.assertFunctionAuth("selffactory/update");
			SelfFactory entity = AppUtil.toObject(data, SelfFactory.class);
			return WebUtil.getSuccessMap(aSelfFactoryService.updateSelfFactory(entity));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}

	/**
	 * 删除实体
	 * @param id 主键
	 * @return id
	 */
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> deleteSelfFactory(@RequestParam(value = "id") int key) {
		try{
			aCoreService.assertFunctionAuth("selffactory/delete");
			return WebUtil.getSuccessMap(aSelfFactoryService.deleteSelfFactory(key));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}
	
}

